package com.example.myblog_ssm.controller;

import com.example.myblog_ssm.common.AjaxResult;
import com.example.myblog_ssm.entity.Comment;
import com.example.myblog_ssm.service.CommentService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22479
 * Date: 2023-03-29
 * Time: 15:51
 */
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Resource
    private CommentService commentService;

    /**
     * 发布评论
     *
     * @param comment
     * @return
     */
    @RequestMapping("/putcomment")
    public AjaxResult putComment(Comment comment) {
        if (comment == null || comment.getAid() < 0) {
            return AjaxResult.fail(-1, "参数错误");
        }
        return AjaxResult.success(commentService.putComment(comment));
    }


    /**
     * 读取评论
     *
     * @param aid
     * @return
     */
    @RequestMapping("/getcomment")
    public AjaxResult getComment(Integer aid) {
        if (aid == null || aid < 0) {
            return AjaxResult.fail(-1, "参数错误");
        }
        List<Comment> list = commentService.getComment(aid);
        return AjaxResult.success(list);
    }
}
